/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.z100h.supplychain.order.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.z100h.supplychain.order.entity.Order;
import com.z100h.supplychain.order.entity.OrderVo;
import com.z100h.supplychain.order.mapper.OrderMapper;

/**
 * 订单Service
 * @author fyh
 * @version 2019-04-15
 */
@Service
@Transactional(readOnly = true)
public class OrderService extends CrudService<OrderMapper, Order> {

	@Autowired
	private OrderMapper orderMapper;

	@Override
	public Order get(String id) {
		return super.get(id);
	}

	@Override
	public List<Order> findList(Order order) {
		return super.findList(order);
	}

	@Override
	public Page<Order> findPage(Page<Order> page, Order order) {
		return super.findPage(page, order);
	}

	@Override
	@Transactional(readOnly = false)
	public void save(Order order) {
		super.save(order);
	}

	@Override
	@Transactional(readOnly = false)
	public void delete(Order order) {
		super.delete(order);
	}

	public void updateOrderStockoutId(String evidenceId, List<String> serviceIds) {
		orderMapper.updateOrderStockoutId(evidenceId, serviceIds);
	}

	public void updateRepairStockoutId(String evidenceId, List<String> serviceIds) {
		orderMapper.updateRepairStockoutId(evidenceId, serviceIds);
	}

	public List<String> findOrderIdsByEvidenceId(String evidenceId) {
		return orderMapper.findOrderIdsByEvidenceId(evidenceId);
	}

	public List<String> findRepairIdsByEvidenceId(String evidenceId) {
		return orderMapper.findRepairIdsByEvidenceId(evidenceId);
	}

	public String getStockroomIdByStockoutId(String stockoutId) {
		return orderMapper.getStockroomIdByStockoutId(stockoutId);
	}

	public List<String> findOrderIdsByEvidenceIds(List<String> evidenceIds) {
		return orderMapper.findOrderIdsByEvidenceIds(evidenceIds);
	}

	public String getRentType(String orderId) {
		return orderMapper.getRentType(orderId);
	}

	public List<String> findListByStockroomId(String stockroomId) {
		return orderMapper.findListByStockroomId(stockroomId);
	}

	public List<String> findList(String stockroomId, String isSupplement) {
		return orderMapper.findOrderList(stockroomId, isSupplement);
	}

	public List<String> findRepairList(String stockroomId) {
		return orderMapper.findRepairList(stockroomId);
	}

	public void updateOrderStockoutId(String evidenceId, String orderId) {
		orderMapper.updateOrderStockoutIdByOrderId(evidenceId, orderId);
	}

	public Page<OrderVo> findByPage(Page<OrderVo> page, OrderVo orderVo) {

		dataRuleFilter(orderVo);
		orderVo.setPage(page);
		page.setList(orderMapper.findByPage(orderVo));
		return page;
	}

	public void updateOrderPurchasePrice(List<String> orderIds) {
		String targetMonth = DateUtils.formatDate(new Date(), "M");
		orderMapper.updateOrderPurchasePrice(orderIds, targetMonth);
	}

	public void updateRepairPurchasePrice(List<String> repairIds) {
		String targetMonth = DateUtils.formatDate(new Date(), "M");
		orderMapper.updateRepairPurchasePrice(repairIds, targetMonth);
	}
}